package ali.compass;


import ali.point.Point;

/**
 * Created by IntelliJ IDEA.
 * User: aliolci
 * Date: 20/05/11
 * Time: 21:55
 * To change this template use File | Settings | File Templates.
 */
public class Compass {
    private int horizontalDirection;
    private int verticalDirection;

    public int getHorizontalDirectionMathSign() {
        return horizontalDirection;
    }

    public int getVerticalDirectionMathSign() {
        return verticalDirection;
    }

    private Compass(CompassDirection horizontalDirection, CompassDirection  verticalDirection) {
        this.horizontalDirection=horizontalDirection.getValue();
        this.verticalDirection=verticalDirection.getValue();
    }

    public static Compass getCompass(Point source, Point  destination){
        return new Compass(getHorizontalCompassDirection(source,destination), getVerticalCompassDirection(source,destination));
    }

    private static CompassDirection getVerticalCompassDirection(Point source, Point destination) {
        float diffY =source.getY()-destination.getY();
        if(diffY<0){
            return CompassDirection.S;
        } else if(diffY>0) {
            return CompassDirection.N;
        } else {
            return CompassDirection.O;
        }
    }

    private static CompassDirection getHorizontalCompassDirection(Point source, Point destination) {
        float diffX = source.getX()-destination.getX();
        if(diffX<0){
            return CompassDirection.E;
        } else if(diffX>0) {
            return CompassDirection.W;
        } else {
            return CompassDirection.O;
        }
    }
}
